"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.computed = void 0;
var effect_1 = require("./effect");
var utils_1 = require("../utils");
/**
 * 计算属性
 * @param getter {Function} 监听的方法（需返回值）
 * @return {Ref} 返回一个ref对象
 */
function computed(getter) {
    if (!utils_1.isFunction(getter)) { // getter必须是个方法
        console.error("computed\u53C2\u6570\u5FC5\u987B\u662F\u4E2A\u65B9\u6CD5");
        return;
    }
    var value = getter();
    var depsMap = effect_1.createDepsMap();
    function computedEffect() { value = getter(); effect_1.trigger(depsMap, 'value'); }
    var computed = {
        __v_isRef: true,
        get value() {
            effect_1.track(depsMap, 'value');
            return value;
        },
        set value(newVal) {
            console.error('computed 属性不可修改');
        }
    };
    effect_1.effect(computedEffect); // 监听方法
    return computed;
}
exports.computed = computed;
